package com.web.core.base.dao;

import org.springframework.stereotype.Repository;

import com.blue.jdbc.BaseDao;
import com.web.core.base.model.Area;

@Repository
public class AreaDao extends BaseDao<Area>
{
	public AreaDao()
	{
	}

	@Override
	protected void query(StringBuilder sql, Area param)
	{
		if (param != null)
		{
			if (param.getState() != null)
				sql.append(" and a.state=:state");

			if (param.getCode() != null && !param.getCode().isEmpty())
				sql.append(" and a.code=:code");
			
			if (param.getParentId() != null && param.getParentId() > 0)
				sql.append(" and a.parent_id=:parentId");
			
		}
	}
	
	public boolean existParent(Integer parentId)
	{
		String sql = "select count(*) from base_area where id=?";
		int n = jdbcTemplate.queryForObject(sql, Integer.class, parentId);
		return n > 0;
	}

}
